package com.aruba.controller;

import com.aruba.bean.User;
import com.aruba.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("login.do")
    @ResponseBody
    public String login(String name) {
        User user = userService.findUser(name);
        if (user != null) {
            return "success";
        }

        int a = 1 / 0;

        return "login failed";
    }

//    @ExceptionHandler
    public ModelAndView handlerException(Exception e) {
        System.out.println(e.toString());
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("err");
        return modelAndView;
    }
}
